/*
 * @Author: Otway
 * @Date: 2019-01-09 11:16:08
 * @LastEditors: Otway
 * @LastEditTime: 2019-08-30 18:50:09
 * @copyright: h-visions
 */
import React, { PureComponent } from 'react';
import {
    Row,
    Col,
    Form,
    Input,
    Select,
    InputNumber,
    DatePicker
} from 'antd';
import moment from 'moment';
const dateFormat = 'YYYY/MM/DD';
const FormItem = Form.Item;
const { Option } = Select
const { WeekPicker } = DatePicker;
const formItemLayout = {
    // 抽屉里面Form。二列的布局比例
    labelCol: {
        span: 7
    },
    wrapperCol: {
        span: 17
    }
};
class AddFrom extends PureComponent {
    state = {
    }
    render() {
        const {
            formData,
            one,
            form: { getFieldDecorator },
        } = this.props;
        console.log(one);
        return (
            <Form >
                <Row>
                    <Col span={12}>
                        <FormItem {...formItemLayout} label={'机型:'}>
                            {getFieldDecorator('model', {
                                initialValue: one ? formData.model : null,
                                rules: [
                                    {
                                        required: true,
                                        message: '机型不能为空'
                                    }
                                ],
                                getValueFromEvent: (event) => {
                                    return event.target.value.replace(/\s+/g, "")
                                },
                            })(<Input placeholder='输入机型' allowClear maxLength={20} />)}
                        </FormItem>
                    </Col>
                    <Col span={12}>
                        <FormItem {...formItemLayout} label={'批号:'}>
                            {getFieldDecorator('batchNo', {
                                initialValue: one ? formData.batchNo : null,
                                rules: [
                                    {
                                        required: true,
                                        message: '批号不能为空'
                                    }
                                ],
                                getValueFromEvent: (event) => {
                                    return event.target.value.replace(/\s+/g, "")
                                },
                            })(<Input placeholder='输入批号' allowClear maxLength={20} />)}
                        </FormItem>
                    </Col>
                    <Col span={12}>
                        <FormItem {...formItemLayout} label={'装配机号:'}>
                            {getFieldDecorator('assemblyNo', {
                                initialValue: one ? formData.assemblyNo : null,
                                rules: [
                                    {
                                        required: true,
                                        message: '装配机号不能为空'
                                    }
                                ],
                                getValueFromEvent: (event) => {
                                    return event.target.value.replace(/\s+/g, "")
                                },
                            })(<Input placeholder='输入装配机号' allowClear maxLength={20} />)}
                        </FormItem>
                    </Col>
                    <Col span={12}>
                        <FormItem {...formItemLayout} label={'车间:'}>
                            {getFieldDecorator('attributeFirst', {
                                initialValue: one ? formData.attributeFirst : null,
                                rules: [
                                    {
                                        required: true,
                                        message: '车间不能为空'
                                    }
                                ],
                                getValueFromEvent: (event) => {
                                    return event.target.value.replace(/\s+/g, "")
                                },
                            })(<Input placeholder='输入车间' allowClear maxLength={20} />)}
                        </FormItem>
                    </Col>
                    <Col span={12}>
                        <FormItem {...formItemLayout} label={'备注:'}>
                            {getFieldDecorator('remark', {
                                initialValue: one ? formData.remark : null,
                                rules: [
                                    {
                                        required: false,
                                        message: '备注不能为空'
                                    }
                                ],
                                getValueFromEvent: (event) => {
                                    return event.target.value.replace(/\s+/g, "")
                                },
                            })(<Input placeholder='输入备注' allowClear maxLength={20} />)}
                        </FormItem>
                    </Col>
                    <Col span={12}>
                        <FormItem {...formItemLayout} label={'装配部门:'}>
                            {getFieldDecorator('assemblyDept', {
                                initialValue: one ? formData.assemblyDept : null,
                                rules: [
                                    {
                                        required: true,
                                        message: '装配部门不能为空'
                                    }
                                ]
                            })(<Select allowClear={true}>
                                <Option value={'总装'} key={1}>总装</Option>
                                <Option value={'总装1'} key={2}>总装1</Option>
                                <Option value={'总装12'} key={3}>总装12</Option>
                                <Option value={'总装123'} key={4}>总装123</Option>
                            </Select>)}
                        </FormItem>
                    </Col>
                    <Col span={12}>
                        <FormItem {...formItemLayout} label={'客户:'}>
                            {getFieldDecorator('customer', {
                                initialValue: one ? formData.customer : null,
                                rules: [
                                    {
                                        required: false,
                                        message: '客户不能为空'
                                    }
                                ],
                                getValueFromEvent: (event) => {
                                    return event.target.value.replace(/\s+/g, "")
                                },
                            })(<Input placeholder='输入客户' allowClear maxLength={20} />)}
                        </FormItem>
                    </Col>
                    {
                        one === false ? <Col span={12}>
                            <FormItem {...formItemLayout} label={'计划周:'}>
                                {getFieldDecorator('week', {
                                    initialValue: formData.week !== null && formData.week !== undefined ? moment(formData.week, 'YYYY/wo') : null,
                                    rules: [
                                        {
                                            required: true,
                                            message: '计划周不能为空'
                                        }
                                    ]
                                })(
                                    <WeekPicker allowClear />
                                )}
                            </FormItem>
                        </Col> : null
                    }
                    {/* <Col span={12}>
                        <FormItem {...formItemLayout} label={'资料输出时间:'}>
                            {getFieldDecorator('dataOutputTime', {
                                initialValue: one ? (formData.dataOutputTime !== null && formData.dataOutputTime !== undefined ? moment(formData.dataOutputTime, dateFormat) : null) : null,
                                rules: [
                                    {
                                        required: false,
                                        message: '资料输出时间不能为空'
                                    }
                                ]
                            })(
                                <DatePicker format={dateFormat} allowClear />
                            )}
                        </FormItem>
                    </Col> */}
                    <Col span={12}>
                        <FormItem {...formItemLayout} label={'装配开始时间:'}>
                            {getFieldDecorator('assembleStartTime', {
                                initialValue: one ? (formData.assembleStartTime !== null && formData.assembleStartTime !== undefined ? moment(formData.assembleStartTime, dateFormat) : null) : null,
                                rules: [
                                    {
                                        required: false,
                                        message: '装配开始时间不能为空'
                                    }
                                ]
                            })(<DatePicker allowClear format={dateFormat} />)}
                        </FormItem>
                    </Col>
                    <Col span={12}>
                        <FormItem {...formItemLayout} label={'第一交机时间:'}>
                            {getFieldDecorator('firstDeliveryTime', {
                                initialValue: one ? (formData.firstDeliveryTime !== null && formData.firstDeliveryTime !== undefined ? moment(formData.firstDeliveryTime, dateFormat) : null) : null,
                                rules: [
                                    {
                                        required: false,
                                        message: '第一交机时间不能为空'
                                    }
                                ]
                            })(<DatePicker allowClear format={dateFormat} />)}
                        </FormItem>
                    </Col>
                    {/* <Col span={12}>
                        <FormItem {...formItemLayout} label={'试机/补漆/包装结束:'}>
                            {getFieldDecorator('endTime', {
                                initialValue: one ? (formData.endTime !== null && formData.endTime !== undefined ? moment(formData.endTime, dateFormat) : null) : null,
                                rules: [
                                    {
                                        required: false,
                                        message: '试机/补漆/包装结束时间不能为空'
                                    }
                                ]
                            })(
                                <DatePicker allowClear format={dateFormat} />
                            )}
                        </FormItem>
                    </Col> */}
                    <Col span={12}>
                        <FormItem {...formItemLayout} label={'第一出机时间:'}>
                            {getFieldDecorator('firstOutputTime', {
                                initialValue: one ? (formData.firstOutputTime !== null && formData.firstOutputTime !== undefined ? moment(formData.firstOutputTime, dateFormat) : null) : null,
                                rules: [
                                    {
                                        required: false,
                                        message: '第一出机时间不能为空'
                                    }
                                ]
                            })(
                                <DatePicker allowClear format={dateFormat} />
                            )}
                        </FormItem>
                    </Col>
                    <Col span={12}>
                        <FormItem {...formItemLayout} label={'机架:'}>
                            {getFieldDecorator('rack', {
                                initialValue: one ? (formData.rack !== null && formData.rack !== undefined ? moment(formData.rack, dateFormat) : null) : null,
                                rules: [
                                    {
                                        required: false,
                                        message: '机架不能为空'
                                    }
                                ]
                            })(
                                <DatePicker allowClear format={dateFormat} />
                            )}
                        </FormItem>
                    </Col>
                    <Col span={12}>
                        <FormItem {...formItemLayout} label={'机架附件:'}>
                            {getFieldDecorator('rackAffix', {
                                initialValue: one ? (formData.rackAffix !== null && formData.rackAffix !== undefined ? moment(formData.rackAffix, dateFormat) : null) : null,
                                rules: [
                                    {
                                        required: false,
                                        message: '机架附件不能为空'
                                    }
                                ]
                            })(
                                <DatePicker allowClear format={dateFormat} />
                            )}
                        </FormItem>
                    </Col>
                    <Col span={12}>
                        <FormItem {...formItemLayout} label={'机架钣金:'}>
                            {getFieldDecorator('rackPlate', {
                                initialValue: one ? (formData.rackPlate !== null && formData.rackPlate !== undefined ? moment(formData.rackPlate, dateFormat) : null) : null,
                                rules: [
                                    {
                                        required: false,
                                        message: '机架钣金不能为空'
                                    }
                                ]
                            })(
                                <DatePicker allowClear format={dateFormat} />
                            )}
                        </FormItem>
                    </Col>
                    <Col span={12}>
                        <FormItem {...formItemLayout} label={'油缸:'}>
                            {getFieldDecorator('oilCylinder', {
                                initialValue: one ? (formData.oilCylinder !== null && formData.oilCylinder !== undefined ? moment(formData.oilCylinder, dateFormat) : null) : null,
                                rules: [
                                    {
                                        required: false,
                                        message: '油缸不能为空'
                                    }
                                ]
                            })(
                                <DatePicker allowClear format={dateFormat} />
                            )}
                        </FormItem>
                    </Col>
                    <Col span={12}>
                        <FormItem {...formItemLayout} label={'液压油路:'}>
                            {getFieldDecorator('hydraulicCircuit', {
                                initialValue: one ? (formData.hydraulicCircuit !== null && formData.hydraulicCircuit !== undefined ? moment(formData.hydraulicCircuit, dateFormat) : null) : null,
                                rules: [
                                    {
                                        required: false,
                                        message: '液压油路不能为空'
                                    }
                                ]
                            })(
                                <DatePicker allowClear format={dateFormat} />
                            )}
                        </FormItem>
                    </Col>
                    <Col span={12}>
                        <FormItem {...formItemLayout} label={'液压打料:'}>
                            {getFieldDecorator('hydraulicMaterial', {
                                initialValue: one ? (formData.hydraulicMaterial !== null && formData.hydraulicMaterial !== undefined ? moment(formData.hydraulicMaterial, dateFormat) : null) : null,
                                rules: [
                                    {
                                        required: false,
                                        message: '液压打料不能为空'
                                    }
                                ]
                            })(
                                <DatePicker allowClear format={dateFormat} />
                            )}
                        </FormItem>
                    </Col>
                    <Col span={12}>
                        <FormItem {...formItemLayout} label={'柱架:'}>
                            {getFieldDecorator('columnFrame', {
                                initialValue: one ? (formData.columnFrame !== null && formData.columnFrame !== undefined ? moment(formData.columnFrame, dateFormat) : null) : null,
                                rules: [
                                    {
                                        required: false,
                                        message: '柱架不能为空'
                                    }
                                ]
                            })(
                                <DatePicker allowClear format={dateFormat} />
                            )}
                        </FormItem>
                    </Col>
                    <Col span={12}>
                        <FormItem {...formItemLayout} label={'柱架滑座:'}>
                            {getFieldDecorator('columnSlide', {
                                initialValue: one ? (formData.columnSlide !== null && formData.columnSlide !== undefined ? moment(formData.columnSlide, dateFormat) : null) : null,
                                rules: [
                                    {
                                        required: false,
                                        message: '柱架滑座不能为空'
                                    }
                                ]
                            })(
                                <DatePicker allowClear format={dateFormat} />
                            )}
                        </FormItem>
                    </Col>
                    <Col span={12}>
                        <FormItem {...formItemLayout} label={'总装电器:'}>
                            {getFieldDecorator('assemblyElectrical', {
                                initialValue: one ? (formData.assemblyElectrical !== null && formData.assemblyElectrical !== undefined ? moment(formData.assemblyElectrical, dateFormat) : null) : null,
                                rules: [
                                    {
                                        required: false,
                                        message: '总装电器不能为空'
                                    }
                                ]
                            })(
                                <DatePicker allowClear format={dateFormat} />
                            )}
                        </FormItem>
                    </Col>
                    <Col span={12}>
                        <FormItem {...formItemLayout} label={'总装管路:'}>
                            {getFieldDecorator('assemblyLine', {
                                initialValue: one ? (formData.assemblyLine !== null && formData.assemblyLine !== undefined ? moment(formData.assemblyLine, dateFormat) : null) : null,
                                rules: [
                                    {
                                        required: false,
                                        message: '总装管路不能为空'
                                    }
                                ]
                            })(
                                <DatePicker allowClear format={dateFormat} />
                            )}
                        </FormItem>
                    </Col>
                    <Col span={12}>
                        <FormItem {...formItemLayout} label={'外购件:'}>
                            {getFieldDecorator('purchasedPart', {
                                initialValue: one ? (formData.purchasedPart !== null && formData.purchasedPart !== undefined ? moment(formData.purchasedPart, dateFormat) : null) : null,
                                rules: [
                                    {
                                        required: false,
                                        message: '外购件不能为空'
                                    }
                                ]
                            })(
                                <DatePicker allowClear format={dateFormat} />
                            )}
                        </FormItem>
                    </Col>
                    <Col span={12}>
                        <FormItem {...formItemLayout} label={'周边事业部:'}>
                            {getFieldDecorator('peripheralBusinessDivision', {
                                initialValue: one ? (formData.peripheralBusinessDivision !== null && formData.peripheralBusinessDivision !== undefined ? moment(formData.peripheralBusinessDivision, dateFormat) : null) : null,
                                rules: [
                                    {
                                        required: false,
                                        message: '周边事业部不能为空'
                                    }
                                ]
                            })(
                                <DatePicker allowClear format={dateFormat} />
                            )}
                        </FormItem>
                    </Col>
                    <Col span={12}>
                        <FormItem {...formItemLayout} label={'热作业事业部:'}>
                            {getFieldDecorator('hotWorksDivision', {
                                initialValue: one ? (formData.hotWorksDivision !== null && formData.hotWorksDivision !== undefined ? moment(formData.hotWorksDivision, dateFormat) : null) : null,
                                rules: [
                                    {
                                        required: false,
                                        message: '热作业事业部不能为空'
                                    }
                                ]
                            })(
                                <DatePicker allowClear format={dateFormat} />
                            )}
                        </FormItem>
                    </Col>
                    <Col span={12}>
                        <FormItem {...formItemLayout} label={'台量:'}>
                            {getFieldDecorator('stage', {
                                initialValue: one ? formData.stage : null,
                                rules: [
                                    {
                                        required: true,
                                        message: '台量不能为空'
                                    }
                                ]
                            })(<InputNumber min={0} max={9999999999} />)}
                        </FormItem>
                    </Col>
                </Row>
            </Form>
        );
    }
}
export default Form.create()(AddFrom);
